package com.omega.encryptedsql.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.omega.encryptedsql.mapper.EmployeeMapper;
import com.omega.encryptedsql.po.Employee;
import com.omega.encryptedsql.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author omega
 * @description: TODO
 * @date 2025/7/10
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService  {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee getEmployeeById(Long id) {
        return getById(id);
    }

    @Override
    public boolean saveEmployee(Employee employee) {
        return save(employee);
    }

    @Override
    public Page<Employee> listEmployees(Page<Employee> page) {
        return page(page);
    }

    @Override
    public boolean updateEmployee(Employee employee) {
        return updateById(employee);
    }

    @Override
    public List<Employee> searchWithName(String name) {
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Employee::getName, name);
        List<Employee> employeeList = this.getBaseMapper().selectList(queryWrapper);
        //return employeeMapper.searchWithName(name);
        return employeeList;
    }

    @Override
    public List<Employee> searchWithNameNoLambda(String name) {
        return employeeMapper.searchWithName(name);
    }
}
